
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>五、事务 · 计算机笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="海拉尔的三角">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro-fixed/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-ancre-navigation/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex-pro/katex.min.css">
                
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-terminull-light/terminull.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="index_withNum.html" />
    
    
    <link rel="prev" href="operatorData_withNum.html" />
    

    
        <link rel="shortcut icon" href="image/ico.png" type="image/x-icon">
    
    
    
    
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="image/ico.png">
    
    
        
    
    
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://github.com/spite-triangle" target="_blank" class="custom-link">Github</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../cpp/cpp.html">
            
                <a href="../../cpp/cpp.html">
            
                    
                    C/C++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../../cpp/chapter/foundation_withNum.html">
            
                <a href="../../cpp/chapter/foundation_withNum.html">
            
                    
                    一、基础概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../../cpp/chapter/keyword_withNum.html">
            
                <a href="../../cpp/chapter/keyword_withNum.html">
            
                    
                    二、关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../../cpp/chapter/point_reference_withNum.html">
            
                <a href="../../cpp/chapter/point_reference_withNum.html">
            
                    
                    三、指针与引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../../cpp/chapter/oop_withNum.html">
            
                <a href="../../cpp/chapter/oop_withNum.html">
            
                    
                    四、面向对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../../cpp/chapter/memory_withNum.html">
            
                <a href="../../cpp/chapter/memory_withNum.html">
            
                    
                    五、内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../../cpp/chapter/process_withNum.html">
            
                <a href="../../cpp/chapter/process_withNum.html">
            
                    
                    六、进程与线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../../cpp/chapter/locks_withNum.html">
            
                <a href="../../cpp/chapter/locks_withNum.html">
            
                    
                    七、锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../../cpp/chapter/stl_withNum.html">
            
                <a href="../../cpp/chapter/stl_withNum.html">
            
                    
                    八、STL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="../../cpp/chapter/dataStruction_withNum.html">
            
                <a href="../../cpp/chapter/dataStruction_withNum.html">
            
                    
                    九、数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="../../cpp/chapter/array_list_withNum.html">
            
                <a href="../../cpp/chapter/array_list_withNum.html">
            
                    
                    十、数组链表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="../../cpp/chapter/find_withNum.html">
            
                <a href="../../cpp/chapter/find_withNum.html">
            
                    
                    十一、目标查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="../../cpp/chapter/tree_withNum.html">
            
                <a href="../../cpp/chapter/tree_withNum.html">
            
                    
                    十二、树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="../../cpp/chapter/binaryTree_withNum.html">
            
                <a href="../../cpp/chapter/binaryTree_withNum.html">
            
                    
                    十三、二叉树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="../../cpp/chapter/dynamicProgram_withNum.html">
            
                <a href="../../cpp/chapter/dynamicProgram_withNum.html">
            
                    
                    十四、动态规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="../../cpp/chapter/backtracking_withNum.html">
            
                <a href="../../cpp/chapter/backtracking_withNum.html">
            
                    
                    十五、回溯算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="../../cpp/chapter/monotoneStack_withNum.html">
            
                <a href="../../cpp/chapter/monotoneStack_withNum.html">
            
                    
                    十六、单调栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="../../cpp/chapter/toollib_withNum.html">
            
                <a href="../../cpp/chapter/toollib_withNum.html">
            
                    
                    附录 工具库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../mysql.html">
            
                <a href="../mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="introduction_withNum.html">
            
                <a href="introduction_withNum.html">
            
                    
                    一、简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="foundation_withNum.html">
            
                <a href="foundation_withNum.html">
            
                    
                    二、控制台操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="operatorDB_withNum.html">
            
                <a href="operatorDB_withNum.html">
            
                    
                    三、数据库、表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="operatorData_withNum.html">
            
                <a href="operatorData_withNum.html">
            
                    
                    四、数据操作
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.1.5" data-path="transaction_withNum.html">
            
                <a href="transaction_withNum.html">
            
                    
                    五、事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6" data-path="index_withNum.html">
            
                <a href="index_withNum.html">
            
                    
                    六、索引
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.7" data-path="authority_withNum.html">
            
                <a href="authority_withNum.html">
            
                    
                    七、权限管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.8" data-path="backup_withNum.html">
            
                <a href="backup_withNum.html">
            
                    
                    八、备份
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../linux/linux.html">
            
                <a href="../../linux/linux.html">
            
                    
                    Linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../../linux/chapter/foundation_withNum.html">
            
                <a href="../../linux/chapter/foundation_withNum.html">
            
                    
                    一、原理知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../../linux/chapter/command_withNum.html">
            
                <a href="../../linux/chapter/command_withNum.html">
            
                    
                    二、指令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../tcp_udp/tcp_upd.html">
            
                <a href="../../tcp_udp/tcp_upd.html">
            
                    
                    网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="../../tcp_udp/chapter/foundation_withNum.html">
            
                <a href="../../tcp_udp/chapter/foundation_withNum.html">
            
                    
                    一、网络通讯基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                <a href="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                    
                    二、tcp/udp
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >五、事务</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><span class="title-icon "></span><a href="#&#x4E8B;&#x52A1;"><b></b>&#x4E8B;&#x52A1;</a></li><li><span class="title-icon "></span><a href="#1-&#x4E8B;&#x52A1;&#x6982;&#x5FF5;"><b></b>1. &#x4E8B;&#x52A1;&#x6982;&#x5FF5;</a></li><li><span class="title-icon "></span><a href="#2-acid&#x539F;&#x5219;"><b></b>2. ACID&#x539F;&#x5219;</a></li><ul><li><span class="title-icon "></span><a href="#21-&#x4ECB;&#x7ECD;"><b></b>2.1. &#x4ECB;&#x7ECD;</a></li><li><span class="title-icon "></span><a href="#22-&#x9694;&#x79BB;&#x6240;&#x5BFC;&#x81F4;&#x7684;&#x95EE;&#x9898;"><b></b>2.2. &#x9694;&#x79BB;&#x6240;&#x5BFC;&#x81F4;&#x7684;&#x95EE;&#x9898;</a></li><ul><li><span class="title-icon "></span><a href="#221-&#x810F;&#x8BFB;"><b></b>2.2.1. &#x810F;&#x8BFB;</a></li><li><span class="title-icon "></span><a href="#222-&#x4E0D;&#x53EF;&#x91CD;&#x590D;&#x8BFB;"><b></b>2.2.2. &#x4E0D;&#x53EF;&#x91CD;&#x590D;&#x8BFB;</a></li><li><span class="title-icon "></span><a href="#223-&#x5E7B;&#x8BFB;"><b></b>2.2.3. &#x5E7B;&#x8BFB;</a></li></ul></ul><li><span class="title-icon "></span><a href="#3-sql&#x64CD;&#x4F5C;"><b></b>3. SQL&#x64CD;&#x4F5C;</a></li><ul><li><span class="title-icon "></span><a href="#31-&#x4E8B;&#x52A1;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;"><b></b>3.1. &#x4E8B;&#x52A1;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;</a></li><li><span class="title-icon "></span><a href="#32-&#x5B58;&#x6863;&#x70B9;-&#x4E86;&#x89E3;"><b></b>3.2. &#x5B58;&#x6863;&#x70B9; (&#x4E86;&#x89E3;)</a></li><li><span class="title-icon "></span><a href="#33-&#x4E8B;&#x52A1;"><b></b>3.3. &#x4E8B;&#x52A1;</a></li></ul><li><span class="title-icon "></span><a href="#4-&#x884C;&#x7EA7;&#x9501;"><b></b>4. &#x884C;&#x7EA7;&#x9501;</a></li></ul></div><a href="#&#x4E8B;&#x52A1;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 style="font-size:60px;text-align:center;" id="&#x4E8B;&#x52A1;"><a name="&#x4E8B;&#x52A1;" class="anchor-navigation-ex-anchor" href="#&#x4E8B;&#x52A1;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E8B;&#x52A1;</h1>

<h1 id="1-&#x4E8B;&#x52A1;&#x6982;&#x5FF5;"><a name="1-&#x4E8B;&#x52A1;&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#1-&#x4E8B;&#x52A1;&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x4E8B;&#x52A1;&#x6982;&#x5FF5;</h1>
<blockquote>
<p>[!note]
<strong>&#x6982;&#x5FF5;&#xFF1A;&#x4E00;&#x6BB5;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#xFF0C;&#x8981;&#x4E48;&#x5168;&#x90E8;&#x6210;&#x529F;&#xFF0C;&#x8981;&#x4E48;&#x5168;&#x90E8;&#x5931;&#x8D25;&#xFF0C;&#x4E0D;&#x5141;&#x8BB8;&#x67D0;&#x90E8;&#x5206;&#x6210;&#x529F;&#x7684;&#x60C5;&#x51B5;&#x3002;</strong>
<strong>&#x4EE3;&#x7801;&#x5B9E;&#x73B0;&#xFF1A;&#x5C31;&#x662F;&#x5C06;&#x4E00;&#x7EC4;<code>SQL</code>&#x4EE3;&#x7801;&#x653E;&#x5230;&#x4E00;&#x4E2A;&#x6279;&#x6B21;&#x4E2D;&#x6267;&#x884C;&#x3002;</strong></p>
</blockquote>
<h1 id="2-acid&#x539F;&#x5219;"><a name="2-acid&#x539F;&#x5219;" class="anchor-navigation-ex-anchor" href="#2-acid&#x539F;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>2. <code>ACID</code>&#x539F;&#x5219;</h1>
<p>&#x53C2;&#x8003;&#x535A;&#x5BA2;&#xFF1A;<a href="https://blog.csdn.net/dengjili/article/details/82468576" target="_blank">&#x4E8B;&#x52A1;ACID&#x7406;&#x89E3;</a></p>
<h2 id="21-&#x4ECB;&#x7ECD;"><a name="21-&#x4ECB;&#x7ECD;" class="anchor-navigation-ex-anchor" href="#21-&#x4ECB;&#x7ECD;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1. &#x4ECB;&#x7ECD;</h2>
<table>
<thead>
<tr>
<th>&#x6982;&#x5FF5;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x539F;&#x5B50;&#x6027;(atomicity)</td>
<td>&#x6574;&#x4E2A;&#x8FC7;&#x7A0B;&#x8981;&#x4E48;&#x5168;&#x90E8;&#x6210;&#x529F;&#xFF0C;&#x8981;&#x4E48;&#x5168;&#x90E8;&#x5931;&#x8D25;</td>
</tr>
<tr>
<td>&#x4E00;&#x81F4;&#x6027;(consistency)</td>
<td>&#x64CD;&#x4F5C;&#x540E;&#x4E0E;&#x64CD;&#x4F5C;&#x524D;&#xFF0C;&#x6570;&#x636E;&#x72B6;&#x6001;&#x4E00;&#x81F4;</td>
</tr>
<tr>
<td>&#x9694;&#x79BB;&#x6027;(isolation)</td>
<td>&#x591A;&#x7528;&#x6237;&#x5E76;&#x53D1;&#xFF0C;&#x4E0D;&#x4F1A;&#x76F8;&#x4E92;&#x5F71;&#x54CD;</td>
</tr>
<tr>
<td>&#x6301;&#x4E45;&#x6027;(durability)</td>
<td>&#x4E8B;&#x52A1;&#x300C;<strong>&#x63D0;&#x4EA4;</strong>&#x300D;&#x5230;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x6570;&#x636E;&#x5E93;&#x6539;&#x53D8;&#x4E14;&#x4E0D;&#x53EF;&#x9006;(<strong>&#x56DE;&#x6EDA;&#x65E0;&#x6548;</strong>) <br> &#x4E8B;&#x52A1;&#x6CA1;&#x6709;&#x63D0;&#x4EA4;&#x5230;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x6570;&#x636E;&#x5E93;&#x6062;&#x590D;&#x539F;&#x72B6;&#xFF08;<strong>&#x6570;&#x636E;&#x5E93;&#x56DE;&#x6EDA;</strong>&#xFF09;</td>
</tr>
</tbody>
</table>
<h2 id="22-&#x9694;&#x79BB;&#x6240;&#x5BFC;&#x81F4;&#x7684;&#x95EE;&#x9898;"><a name="22-&#x9694;&#x79BB;&#x6240;&#x5BFC;&#x81F4;&#x7684;&#x95EE;&#x9898;" class="anchor-navigation-ex-anchor" href="#22-&#x9694;&#x79BB;&#x6240;&#x5BFC;&#x81F4;&#x7684;&#x95EE;&#x9898;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2. &#x9694;&#x79BB;&#x6240;&#x5BFC;&#x81F4;&#x7684;&#x95EE;&#x9898;</h2>
<h3 id="221-&#x810F;&#x8BFB;"><a name="221-&#x810F;&#x8BFB;" class="anchor-navigation-ex-anchor" href="#221-&#x810F;&#x8BFB;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.1. &#x810F;&#x8BFB;</h3>
<p><strong><code>A,B</code>&#x4E8B;&#x52A1;&#x540C;&#x65F6;&#x5BF9;&#x300C;&#x540C;&#x4E00;&#x6570;&#x636E;&#x300D;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#xFF0C;<code>A</code>&#x5728;&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;&#x5E76;&#x300C;&#x8FD8;&#x672A;&#x63D0;&#x4EA4;&#x300D;&#xFF0C;<code>B</code>&#x5728;&#x300C;&#x6570;&#x636E;&#x6700;&#x5F00;&#x59CB;&#x7684;&#x72B6;&#x6001;&#x300D;&#x4E0A;&#x8FDB;&#x884C;&#x4E86;&#x4FEE;&#x6539;&#x5E76;&#x63D0;&#x4EA4;&#x3002;&#x8FD9;&#x6837;<code>B</code>&#x5C31;&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x4E86;&#x810F;&#x8BFB;&#x3002;</strong></p>
<blockquote>
<p>[!note|style:flat]
<span style="color:blue;font-weight:bold"> &#x8FD8;&#x6709;&#x4E8B;&#x52A1;&#x5728;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x8FDB;&#x884C;&#x6570;&#x636E;&#x83B7;&#x53D6;&#xFF0C;&#x63D0;&#x4EA4;&#x4FEE;&#x6539;&#x3002; </span></p>
</blockquote>
<h3 id="222-&#x4E0D;&#x53EF;&#x91CD;&#x590D;&#x8BFB;"><a name="222-&#x4E0D;&#x53EF;&#x91CD;&#x590D;&#x8BFB;" class="anchor-navigation-ex-anchor" href="#222-&#x4E0D;&#x53EF;&#x91CD;&#x590D;&#x8BFB;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.2. &#x4E0D;&#x53EF;&#x91CD;&#x590D;&#x8BFB;</h3>
<p><strong>&#x5728;<code>A</code>&#x4E8B;&#x52A1;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x591A;&#x6B21;&#x5BF9;&#x7EDF;&#x4E00;&#x884C;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x300C;&#x8BFB;&#x53D6;&#x300D;&#x3002;&#x5728;&#x6B64;&#x671F;&#x95F4;&#x6709;&#x5176;&#x4ED6;&#x4E8B;&#x52A1;&#x300C;&#x5BF9;&#x6570;&#x636E;&#x4FEE;&#x6539;&#x300D;&#x5B8C;&#x6210;&#x4E86;&#x63D0;&#x4EA4;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x4F1A;&#x5BFC;&#x81F4;<code>A</code>&#x4E8B;&#x52A1;&#x7684;&#x591A;&#x6B21;&#x8BFB;&#x53D6;&#x300C;&#x6570;&#x636E;&#x503C;&#x4E0D;&#x4E00;&#x6837;&#x300D;&#x3002;</strong></p>
<blockquote>
<p>[!note|style:flat]
<span style="color:blue;font-weight:bold"> &#x591A;&#x6B21;&#x8BFB;&#x540C;&#x4E00;&#x4F4D;&#x7F6E;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x503C;&#x4E0D;&#x4E00;&#x6837; </span></p>
</blockquote>
<h3 id="223-&#x5E7B;&#x8BFB;"><a name="223-&#x5E7B;&#x8BFB;" class="anchor-navigation-ex-anchor" href="#223-&#x5E7B;&#x8BFB;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2.3. &#x5E7B;&#x8BFB;</h3>
<p><strong>&#x5728;<code>A</code>&#x4E8B;&#x52A1;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x591A;&#x6B21;&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x300C;&#x8BFB;&#x53D6;&#x300D;&#x3002;&#x5728;&#x6B64;&#x671F;&#x95F4;&#x6709;&#x5176;&#x4ED6;&#x4E8B;&#x52A1;&#x300C;&#x6DFB;&#x52A0;&#x4E86;&#x65B0;&#x6570;&#x636E;&#x4FEE;&#x300D;&#x5B8C;&#x6210;&#x4E86;&#x63D0;&#x4EA4;&#xFF0C;&#x8FD9;&#x6837;<code>A</code>&#x4E8B;&#x52A1;&#x524D;&#x540E;&#x8BFB;&#x53D6;&#x7684;&#x300C;&#x6570;&#x636E;&#x91CF;&#x4E0D;&#x4E00;&#x6837;&#x300D;&#x3002;</strong></p>
<blockquote>
<p>[!note|style:flat]
<span style="color:blue;font-weight:bold"> &#x591A;&#x6B21;&#x8BFB;&#x53D6;&#x67D0;&#x51E0;&#x884C;&#x6570;&#x636E;&#xFF0C;&#x7A81;&#x7136;&#x591A;&#x4E86;&#x4E00;&#x884C;&#x6570;&#x636E; </span></p>
</blockquote>
<h1 id="3-sql&#x64CD;&#x4F5C;"><a name="3-sql&#x64CD;&#x4F5C;" class="anchor-navigation-ex-anchor" href="#3-sql&#x64CD;&#x4F5C;"><i class="fa fa-link" aria-hidden="true"></i></a>3. <code>SQL</code>&#x64CD;&#x4F5C;</h1>
<h2 id="31-&#x4E8B;&#x52A1;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;"><a name="31-&#x4E8B;&#x52A1;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;" class="anchor-navigation-ex-anchor" href="#31-&#x4E8B;&#x52A1;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;"><i class="fa fa-link" aria-hidden="true"></i></a>3.1. &#x4E8B;&#x52A1;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;</h2>
<blockquote>
<p>[!note|style:flat]
<strong><code>MySQL</code>&#x9ED8;&#x8BA4;&#x5F00;&#x542F;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;&#x3002;</strong></p>
</blockquote>
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x5173;&#x95ED;</span>
<span class="token keyword">set</span> autocommit <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x5F00;&#x542F;</span>
<span class="token keyword">set</span> autocommit <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre>
<h2 id="32-&#x5B58;&#x6863;&#x70B9;-&#x4E86;&#x89E3;"><a name="32-&#x5B58;&#x6863;&#x70B9;-&#x4E86;&#x89E3;" class="anchor-navigation-ex-anchor" href="#32-&#x5B58;&#x6863;&#x70B9;-&#x4E86;&#x89E3;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2. &#x5B58;&#x6863;&#x70B9; (&#x4E86;&#x89E3;)</h2>
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x5B58;&#x6863;&#x70B9;</span>
<span class="token keyword">savepoint</span> &#x4FDD;&#x5B58;&#x70B9;
<span class="token comment">-- &#x56DE;&#x9000;&#x5B58;&#x6863;&#x70B9;</span>
<span class="token keyword">rollback</span> <span class="token keyword">to</span> &#x4FDD;&#x5B58;&#x70B9;
<span class="token comment">-- &#x5220;&#x9664;&#x5B58;&#x6863;&#x70B9;</span>
<span class="token keyword">release</span> &#x4FDD;&#x5B58;&#x70B9;
</code></pre>
<blockquote>
<p>[!note|style:flat]
&#x4E8B;&#x52A1;&#x5931;&#x8D25;&#x4E86;&#xFF0C;&#x8FD9;&#x5B58;&#x6863;&#x70B9;&#x4E5F;&#x6CA1;&#x5565;&#x7528;&#x4E86;&#x3002;</p>
</blockquote>
<h2 id="33-&#x4E8B;&#x52A1;"><a name="33-&#x4E8B;&#x52A1;" class="anchor-navigation-ex-anchor" href="#33-&#x4E8B;&#x52A1;"><i class="fa fa-link" aria-hidden="true"></i></a>3.3. &#x4E8B;&#x52A1;</h2>
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x5173;&#x95ED;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;</span>
<span class="token keyword">set</span> autocommit <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x5F00;&#x542F;&#x4E8B;&#x52A1;</span>
<span class="token keyword">start</span> <span class="token keyword">transaction</span>

&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x903B;&#x8F91;

<span class="token comment">-- &#x6210;&#x529F;&#xFF1A;&#x63D0;&#x4EA4;</span>
<span class="token keyword">commit</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x5931;&#x8D25;&#xFF1A;&#x56DE;&#x6EDA;&#xFF0C;&#x6062;&#x590D;&#x6570;&#x636E;</span>
<span class="token keyword">rollback</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x5F00;&#x542F;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;</span>
<span class="token keyword">set</span> autocommit <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre>
<blockquote>
<p>[!note|style:flat]</p>
<ul>
<li><strong>&#x9996;&#x5148;&#x8981;&#x5173;&#x95ED;&#x81EA;&#x52A8;&#x63D0;&#x4EA4;&#xFF0C;&#x4E8B;&#x52A1;&#x6267;&#x884C;&#x5B8C;&#x5728;&#x5F00;&#x542F;&#x3002;</strong></li>
<li><strong>&#x5728;<code>commit rollback</code>&#x540E;&#xFF0C;&#x5C31;&#x4F1A;&#x5173;&#x95ED;&#x4E8B;&#x52A1;&#xFF0C;&#x6240;&#x6709;&#x7279;&#x522B;&#x5173;&#x95ED;<code>transaction</code></strong></li>
</ul>
</blockquote>
<h1 id="4-&#x884C;&#x7EA7;&#x9501;"><a name="4-&#x884C;&#x7EA7;&#x9501;" class="anchor-navigation-ex-anchor" href="#4-&#x884C;&#x7EA7;&#x9501;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x884C;&#x7EA7;&#x9501;</h1>
<pre class="language-"><code class="lang-sql"><span class="token keyword">set</span> autocommit <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x67E5;&#x8BE2;</span>
<span class="token keyword">select</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">where</span> id <span class="token operator">=</span> <span class="token number">1</span> <span class="token keyword">for</span> <span class="token keyword">update</span> 

<span class="token comment">-- &#x4FEE;&#x6539;</span>
<span class="token keyword">update</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">set</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span><span class="token operator">=</span>&#x503C; <span class="token keyword">where</span> id <span class="token operator">=</span> <span class="token number">1</span>

<span class="token keyword">commit</span>
<span class="token keyword">set</span> autocommit <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
</code></pre>
<blockquote>
<p>[!note|style:flat]</p>
<ul>
<li><strong><code>select  for update</code>&#xFF1A;&#x9501;&#x6570;&#x636E;&#xFF0C;&#x4E3A;<code>MySQL InnoDB</code> &#x9ED8;&#x8BA4;&#x884C;&#x7EA7;&#x9501;</strong></li>
<li><strong>&#x4E00;&#x6761; <code>SQL</code> &#x8BED;&#x53E5;&#x7528;&#x4E0D;&#x5230;&#x300C;&#x7D22;&#x5F15;&#x300D;&#x662F;&#x4E0D;&#x4F1A;&#x4F7F;&#x7528;&#x884C;&#x7EA7;&#x9501;&#x7684;&#xFF0C;&#x4F1A;&#x4F7F;&#x7528;&#x8868;&#x7EA7;&#x9501;&#x628A;&#x6574;&#x5F20;&#x8868;&#x9501;&#x4F4F;&#x3002;</strong></li>
</ul>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="operatorData_withNum.html" class="navigation navigation-prev " aria-label="Previous page: 四、数据操作">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="index_withNum.html" class="navigation navigation-next " aria-label="Next page: 六、索引">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"五、事务","level":"3.1.5","depth":2,"next":{"title":"六、索引","level":"3.1.6","depth":2,"path":"MySQL/chapter/index_withNum.md","ref":"MySQL/chapter/index_withNum.md","articles":[]},"previous":{"title":"四、数据操作","level":"3.1.4","depth":2,"path":"MySQL/chapter/operatorData_withNum.md","ref":"MySQL/chapter/operatorData_withNum.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro-fixed","expandable-chapters-small","ancre-navigation","hide-element","code","splitter","insert-logo-link-website","-sharing","sharing-plus","prism","-highlight","flexible-alerts","lightbox","pageview-count","auto-scroll-table","katex-pro","favicon-absolute","sectionx","terminull-light","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"],"lang":{"flow":"typescript"}},"livereload":{},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"auto-scroll-table":{},"code":{"copyButtons":true},"terminull-light":{},"search-pro-fixed":{},"favicon-absolute":{"favicon":"image/ico.png","appleTouchIconPrecomposed152":"image/ico.png","appleTouchIconMore":{},"appleTouchIconPrecomposedMore":{}},"hide-element":{"elements":[".gitbook-link"]},"katex-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"lightbox":{"jquery":true,"sameUuid":false},"insert-logo-link-website":{"url":"image/logo.png","link":"https://space.bilibili.com/27206875","target":"_blank","style":"height: 230px"},"pageview-count":{},"ancre-navigation":{"showLevel":true,"associatedWithSummary":true,"mode":"float","printLog":false,"multipleH1":true,"float":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"expandable-chapters-small":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"qq":true,"all":["douban","facebook","google","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","whatsapp"],"douban":false,"facebook":false,"weibo":true,"whatsapp":false,"twitter":false,"pocket":false,"google":true,"qzone":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"海拉尔的三角","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"计算机笔记","links":{"sidebar":{"Github":"https://github.com/spite-triangle"}},"gitbook":"*"},"file":{"path":"MySQL/chapter/transaction_withNum.md","mtime":"2021-09-14T15:43:13.714Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-14T15:43:23.052Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-terminull-light/terminull.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

